<template>
    <view>
		<view class="groupsbanner">
			<view class="bbooxx">
				<view v-if="jifen != ''" class="top-content">
					<image :src="mini_static_url+'jifen.png'" mode="widthFix"></image>
					<view class="gongxi">恭喜您获得</view>
					<view class="neirong">{{jifen}}<text>积分</text></view>
					<view class="anniu">
						<view class="item item1" data-value="/pages/user-integral/user-integral" @tap="url_event">去看看</view>
						<view class="item" data-value="/pages/index/index" @tap="url_event">回首页</view>
					</view>
				</view>
				<view v-else class="top-content">
					<view class="neirong">{{msg}}</view>
					<view class="anniu">
						<view class="item" data-value="/pages/index/index" @tap="url_event">回首页</view>
					</view>
				</view>
			</view>
		</view>
    </view>
</template>

<script>
    const app = getApp();
	var mini_static_url = app.globalData.get_static_url('qiandao', true);
    export default {
        data() {
            return {
				mini_static_url:mini_static_url,
                jifen:'',
				msg:''
            };
        },
		onLoad(params) {
		},

        onShow() {
			app.globalData.page_event_onshow_handle();
            // 数据加载
            this.init();
        },

        // 下拉刷新
        onPullDownRefresh(e) {
            this.init();
        },

        methods: {
            // 获取数据
            init(e) {
				var params_sys = app.globalData.get_launch_cache_info();
				if(params_sys != null && ((params_sys.rid || null) != null) && parseInt(params_sys.rid) > 0)
				{
					// 再次判断用户是否登录
					// 未登录去登录
					var user = app.globalData.get_user_info(this, "init");
					if (user != false) {
					    // 已正常登录，去获取积分
						this.get_ma_data();
					}
				}else{
					let mmm = '错误的访问，请返回';
					//app.globalData.showToast(mmm);
					this.setData({
						msg:mmm
					});
				}
            },
			
			// 识别二维码行为
			get_ma_data(){
				var params_sys = app.globalData.get_launch_cache_info();
				uni.request({
					url: app.globalData.get_request_url("getma", "index", "qiandao"),
					method: 'POST',
					data: {id:params_sys.rid},
					dataType: 'json',
					success: res => {console.log(res);
						uni.stopPullDownRefresh();
						if (res.data.code == 0) {
							uni.setNavigationBarTitle({
							    title: '恭喜获得积分'
							});
							var data = res.data.data;
							this.setData({
								jifen:data
							});
						} else {
							app.globalData.showToast(res.data.msg);
							this.setData({
								msg:res.data.msg
							});
						}
						// 清理缓存中的rid
						params_sys.rid = 0;
						uni.setStorageSync(app.globalData.data.cache_launch_info_key, params_sys);
					},
					fail: () => {
						uni.stopPullDownRefresh();
						app.globalData.showToast(this.$t('common.internet_error_tips'));
					}
				});
			},

			// url事件
			url_event(e) {
				app.globalData.url_event(e);
			}
        }
    };
</script>
<style>
    @import './ma.css';
</style>